package com.hanock.sm.fork2d;

public class TranslateTransform extends Transform {

	private float txFrom;
	private float txTo;
	private float tyFrom;
	private float tyTo;
	private int timeFrom;
	private int timeTo;
	
	
	public TranslateTransform(float txFrom, float txTo, float tyFrom, float tyTo, int timeFrom, int timeTo) {
		
		this.txFrom = txFrom;
		this.txTo = txTo;
		this.tyFrom = tyFrom;
		this.tyTo = tyTo;
		this.timeFrom = timeFrom;
		this.timeTo = timeTo;
	}
	
	@Override
	public void progress(Node node, int time) {
		super.progress(node, time);
		
		int act = getActionTime() - timeFrom;
		int interval = timeTo - timeFrom;
		
		if (act < 0 || act > interval)
			return;
		
		float a = txFrom + (txTo - txFrom)*1f*act/interval;
		node.setTranslateX(a);
		a = tyFrom + (tyTo - tyFrom)*1f*act/interval;
		node.setTranslateY(a);
	}
	
	@Override
	public boolean isFinished() {
		return getActionTime() > timeTo;
	}

}
